const app = getApp();
import { _get_product_dict, _get_hot_recommend_product} from '../../utils/qiaofinn'
import { nu } from '../../towxml/parse/parse2/entities/maps/entities';
Page({
  data: {
    cardCur: 0,
    gridCol:4,
    categoryList: [],
    hotRecommendProductListData:[],
    next_page: null
  },
  onLoad() {
    this.initData()
  },
  initData(){
    // 产品分类 
    _get_product_dict(res=>{
      if(res.status){
        this.setData({
          categoryList:res.data.category
        })
      }
    })
    // 热门和推荐产品
    _get_hot_recommend_product({}, res=>{
      this.setData({
        hotRecommendProductListData:res.data.dataList,
        next_page:res.data.next
      })
    })
  },
  // 跳转某个分类产品
  toProductListTap(){
    wx.navigateTo({
      url: './list/list',
    })
  },
  // 更多
  toProductMoreTap(){
    wx.navigateTo({
      url: './more/more',
    })
  },
  // 产品详情页
  productDetailTap(res){
    wx.navigateTo({
      url: './detail/detail?product_id='+res.currentTarget.dataset.id,
    })
  },
  onReachBottom:function(){
    if(this.data.next_page){
      _get_hot_recommend_product({currentPage:this.data.next_page}, res=>{
        let hotRecommendProductListData = this.data.hotRecommendProductListData
        this.setData({
          hotRecommendProductListData:hotRecommendProductListData.concat(res.data.dataList),
          next_page:res.data.next
        })
      })
    }else{
      wx.showToast({
        title: '没有更多的数据',
        icon:'none',
      })
    }
  }

})